#include <cstdlib>
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>
using namespace std;

int getroot(vector<int> &father, int x)
{
	if (x != father[x]) {
		father[x] = getroot(father, father[x]);
	}
	return father[x];
}

int unionset(vector<int> &father, int x, int y)
{
	int fx = getroot(father, x);
	int fy = getroot(father, y);
	if (fx == fy) {
		return 0;
	} else {
		father[fx] = fy;
	}
	return 1;
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int n = 0, m = 0;
	cin >> n >> m;

	vector<int> father(n + 1, 0);
	iota(father.begin(), father.end(), 0);

	vector<vector<int>> edges(m, vector<int>(3, 0));
	for (int i = 0; i < m; i++) {
		cin >> edges[i][0] >> edges[i][1] >> edges[i][2];
	}
	auto cmp = [](auto a, auto b) { return a[2] < b[2]; };
	sort(edges.begin(), edges.end(), cmp);

	int ans = 0;
	int cnt = 0;
	for (auto &v : edges) {
		if (unionset(father, v[0], v[1])) {
			cnt++;
			ans += v[2];
		}
	}
	if (cnt == n - 1) {
		cout << ans << endl;
	} else {
		cout << "orz" << endl;
	}
	return 0;
}